import { combineReducers } from 'redux'
import { REQUEST_POSTS, RECEIVE_POSTS } from './actions';

function setRequestFlag(state = {
    type: 'request',
    isFetched: false,
    count: 0,
    color: 'red',
    resData: 'no data',
}, action) {
    console.log('state now is :', state);
    switch(action.type) {
        case REQUEST_POSTS: 
        return Object.assign({}, state, {
            type: 'request',
            isFetched: true,
        });
        case RECEIVE_POSTS: 
        return Object.assign({}, state, {
            type: 'receive',
            isFetech: false,
            count: state.count + 1,
            color: (state.color == 'red' ? 'blue' : 'red'),
            resData: action.res,
        });
    }
}

// const todoApp = combineReducers({
//     setRequestFlag
// })


export default setRequestFlag